<template>
  <div class="app-container drag-container">
    <el-row :gutter="0">
      <el-col :xs="24" :sm="6" :md="5" :lg="4" class="drag-area" id="drag-area">
        <div style="text-align: center; color: #0fa8e7">数据选择</div>

        <el-input
          style="width: 80%"
          placeholder="输入关键字"
          prefix-icon="el-icon-search"
          v-model="filterText"
        >
        </el-input>

        <el-tree
          class="filter-tree"
          :data="data"
          :props="defaultProps"
          @node-click="handleNodeClick"
          :filter-node-method="filterNode"
          ref="tree"
        ></el-tree>
        <div class="drag-tip" id="drag-tip"></div>
      </el-col>

      <el-col :xs="24" :sm="18" :md="18.7" :lg="20" id="drag-content">
        <el-form
          :inline="true"
          :model="queryParams"
          ref="queryForm"
          v-show="showSearch"
          class="demo-form-inline"
        >
          <!--           <el-form-item label="学年名称" prop="schoolYearId">-->
          <!--            <el-select-->
          <!--              v-model="queryParams.schoolYearId"-->
          <!--              placeholder="请选择学年"-->
          <!--              clearable-->
          <!--              @change="searchTermByYear()"-->
          <!--              size="small"-->
          <!--              style="width: 240px"-->
          <!--            >-->
          <!--              &lt;!&ndash;这里要处理学年信息,给一个接口自动获取学院信息，然后点击传参的时候自动选择显示啥&ndash;&gt;-->
          <!--              <el-option-->
          <!--                v-for="item in yearOptions"-->
          <!--                :key="item.index"-->
          <!--                :label="item.name"-->
          <!--                :value="item.id"-->
          <!--              />-->
          <!--            </el-select>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="学期名称" prop="termId">-->
          <!--            <el-select-->
          <!--              v-model="queryParams.termId"-->
          <!--              placeholder="请选择学期"-->
          <!--              clearable-->
          <!--              size="small"-->
          <!--              style="width: 240px"-->
          <!--              @change="searchCollegeByTerm()"-->
          <!--            >-->
          <!--              <el-option-->
          <!--                v-for="item in termNameOptions"-->
          <!--                :key="item.index"-->
          <!--                :label="item.termName"-->
          <!--                :value="item.id"-->
          <!--              />-->
          <!--            </el-select>-->
          <!--          </el-form-item>-->

          <!-- <el-form-item label="学院名称" prop="collegeId">
          <el-select
            v-model="queryParams.collegeId"
            placeholder="请选择学院"
            clearable
            size="small"
            style="width: 240px"
            @change="searchMajorAndCourse()"
          >

            <el-option
              v-for="item in collegeOptions"
              :key="item.index"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="专业名称" prop="majorId">
          <el-select
            v-model="queryParams.majorId"
            placeholder="请选择专业"
            clearable
            size="small"
            style="width: 240px"
            @change="searchClassesByMajor()"
          >
            <el-option
              v-for="item in majorOptions"
              :key="item.index"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item> -->

          <el-form-item label="班级名称" prop="classesId">
            <el-select
              v-model="queryParams.classesId"
              placeholder="请选择班级"
              clearable
              size="small"
              style="width: 240px"
              @change="searchStudentsByClasses()"
            >
              <el-option
                v-for="item in classesOptions"
                :key="item.index"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="学生名称" prop="userId">
            <el-select
              v-model="queryParams.userId"
              placeholder="请选择学生"
              clearable
              size="small"
              style="width: 240px"
            >
              <el-option
                v-for="item in studentOptions"
                :key="item.index"
                :label="item.xm"
                :value="item.userId"
              />
            </el-select>
          </el-form-item>

          <!-- <el-form-item label="课程名称" prop="courseId">
          <el-select
            v-model="queryParams.courseId"
            placeholder="请选择课程"
            clearable
            size="small"
            style="width: 240px"
          >
            <el-option
              v-for="item in courseOptions"
              :key="item.index"
              :label="item.courseName"
              :value="item.id"
            />
          </el-select>
        </el-form-item> -->

          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['org:course:add']"
              >新增
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['org:course:edit']"
              >修改
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['org:course:remove']"
              >删除
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              :loading="exportLoading"
              @click="handleExport"
              v-hasPermi="['org:course:export']"
              >导出
            </el-button>
          </el-col>
          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar>
        </el-row>

        <el-table :data="courseList" style="width: 100%">
          <el-table-column type="selection" width="55" align="center" />

          <el-table-column
            prop="courseName"
            label="课程名称"
            width="180"
          ></el-table-column>
          <el-table-column
            prop="courseCode"
            label="课程编码"
            width="180"
          ></el-table-column>
          <el-table-column
            prop="courseScore"
            label="课程成绩"
            width="180"
          ></el-table-column>
          <el-table-column
            prop="courseState"
            label="学习状态"
            width="180"
          ></el-table-column>
          <el-table-column prop="studentName" label="学生姓名" width="180">
          </el-table-column>

          <el-table-column
            prop="studentCard"
            label="学生学号"
            width="180"
          ></el-table-column>

          <!-- <el-table-column prop="collegeName" label="学院" width="180">
        </el-table-column>

        <el-table-column prop="majorName" label="专业" width="180">
        </el-table-column>

        <el-table-column prop="classesName" label="班级" width="180">
        </el-table-column> -->

          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['org:course:edit']"
                >修改
              </el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['org:course:remove']"
                >删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
        />
      </el-col>
      <!-- 新增教师对应的课程 -->
      <el-dialog :title="title" :visible.sync="open" width="40%" append-to-body>
        <el-form
          label-position="left"
          label-width="80px"
          :model="form"
          ref="form"
          :rules="rules"
        >
          <el-form-item label="学年名称" prop="schoolYearId">
            <el-select
              v-model="form.schoolYearId"
              placeholder="请选择学年"
              clearable
              size="small"
              style="width: 100%"
              @change="addTermByYear(), handleChange('form', 'schoolYearId')"
            >
              <el-option
                v-for="item in yearOptions"
                :key="item.index"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="学期名称" prop="termId">
            <el-select
              v-model="form.termId"
              placeholder="请选择学期"
              clearable
              size="small"
              style="width: 100%"
              @change="addCollegeByTerm(), handleChange('form', 'termId')"
            >
              <el-option
                v-for="item in termNameOptions"
                :key="item.index"
                :label="item.termName"
                :value="item.id"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="学院名称" prop="collegeId">
            <el-select
              v-model="form.collegeId"
              placeholder="请选择学院"
              clearable
              size="small"
              style="width: 100%"
              @change="addMajorAndCourse(), handleChange('form', 'collegeId')"
            >
              <el-option
                v-for="item in collegeOptions"
                :key="item.index"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="专业名称" prop="majorId">
            <el-select
              v-model="form.majorId"
              placeholder="请选择专业"
              clearable
              size="small"
              style="width: 100%"
              @change="addClassesByMajor(), handleChange('form', 'majorId')"
            >
              <el-option
                v-for="item in majorOptions"
                :key="item.index"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="班级名称" prop="classesId">
            <el-select
              v-model="form.classesId"
              placeholder="请选择班级"
              clearable
              size="small"
              style="width: 100%"
              @change="addStudentByClasses(), handleChange('form', 'classesId')"
            >
              <el-option
                v-for="item in classesOptions"
                :key="item.index"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="课程名称" prop="courseId">
            <el-select
              v-model="form.courseId"
              placeholder="请选择课程"
              clearable
              size="small"
              style="width: 100%"
              @change="handleChange('form', 'courseId')"
            >
              <el-option
                v-for="item in courseOptions"
                :key="item.index"
                :label="item.courseName"
                :value="item.id"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="学生名称" prop="userId">
            <el-select
              v-model="form.userId"
              placeholder="请选择学生"
              clearable
              size="small"
              style="width: 100%"
              @change="handleChange('form', 'userId')"
            >
              <el-option
                v-for="item in studentOptions"
                :key="item.index"
                :label="item.xm"
                :value="item.userId"
              />
            </el-select>
          </el-form-item>
        </el-form>

        <span slot="footer" class="dialog-footer">
          <el-button @click="cancel()">取 消</el-button>
          <el-button type="primary" @click="submitForm()">确 定</el-button>
        </span>
      </el-dialog>
    </el-row>
  </div>
</template>

<script>
import {
  listCourse as listStudentCourse,
  getCourse,
  delCourse,
  addCourse,
  updateCourse,
  exportCourse,
} from "@/api/system/studentCourse";

import { listMajor } from "@/api/org/major";
import { listClasses } from "@/api/org/classes";
import { listStudent } from "@/api/system/student";

// import { listStudent } from "@/api/system/student";

// import {
//   listCourse ,
// } from "@/api/system/course";

// 基本课程管理中的课程
import { listCourse } from "@/api/org/course";

import { course } from "@/views/mixins/course/index";

export default {
  name: "studentCourse",
  mixins: [course],
  data() {
    return {
      yearOptions: [],
      termNameOptions: [],
      data: [
        {
          label: "信息工程学院",
          children: [
            {
              label: "数据结构",
              children: [
                {
                  label: "2017学年",
                  children: [
                    {
                      label: "上学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      label: "下学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
                {
                  label: "2018学年",
                  children: [
                    {
                      label: "上学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      label: "下学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
            {
              label: "算法",
              children: [
                {
                  label: "2017学年",
                  children: [
                    {
                      label: "上学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      label: "下学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
                {
                  label: "2018学年",
                  children: [
                    {
                      label: "上学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      label: "下学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
          ],
        },
        {
          label: "数学学院",
          children: [
            {
              label: "数据结构",
              children: [
                {
                  label: "2017学年",
                  children: [
                    {
                      label: "上学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      label: "下学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
                {
                  label: "2018学年",
                  children: [
                    {
                      label: "上学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      label: "下学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
            {
              label: "算法",
              children: [
                {
                  label: "2017学年",
                  children: [
                    {
                      label: "上学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      label: "下学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
                {
                  label: "2018学年",
                  children: [
                    {
                      label: "上学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      label: "下学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
          ],
        },
        {
          label: "土地与城乡规划学院",
          children: [
            {
              label: "数据结构",
              children: [
                {
                  label: "2017学年",
                  children: [
                    {
                      label: "上学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      label: "下学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
                {
                  label: "2018学年",
                  children: [
                    {
                      label: "上学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      label: "下学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
            {
              label: "算法",
              children: [
                {
                  label: "2017学年",
                  children: [
                    {
                      label: "上学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      label: "下学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
                {
                  label: "2018学年",
                  children: [
                    {
                      label: "上学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      label: "下学期",
                      children: [
                        {
                          label: "张老师",
                        },
                        {
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
          ],
        },
      ],

      defaultProps: {
        children: "children",
        label: "label",
      },
      queryParams: {
        teacher: "",
        course: "",
      },
      tableData: [
        {
          teacher: "张三",
          course: "数据结构",
          student: "李明",
          gender: "男",
        },
        {
          teacher: "张三",
          course: "数据结构",
          student: "小红",
          gender: "女",
        },
        {
          teacher: "张三",
          course: "数据结构",
          student: "源华",
          gender: "男",
        },
        {
          teacher: "张三",
          course: "数据结构",
          student: "佳琪",
          gender: "女",
        },
      ],
      // 总条目数
      total: 10,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        schoolYearId: null,
        collegeId: null,
        termId: null,
        courseId: null,
        majorId: null,
        classesId: null,
        userId: null,
        courseName: null,
        courseCode: null,
        startingUnit: null,
        courseNature: null,
        courseAttribute: null,
        courseCredit: null,
      },
      // 添加教师对应课程的弹框
      open: false,
      form: {
        schoolYearId: null,
        collegeId: null,
        termId: null,
        majorId: null,
        classesId: null,
        userId: null,
        courseId: null,
        id: null,
      },

      courseOptions: [
        {
          value: "信息工程学院",
          label: "信息工程学院",
          children: [
            {
              value: "数据结构",
              label: "数据结构",
              children: [
                {
                  value: "2017学年",
                  label: "2017学年",
                  children: [
                    {
                      value: "上学期",
                      label: "上学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      value: "下学期",
                      label: "下学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
                {
                  value: "2018学年",
                  label: "2018学年",
                  children: [
                    {
                      value: "上学期",
                      label: "上学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      value: "下学期",
                      label: "下学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
            {
              vaule: "算法",
              label: "算法",
              children: [
                {
                  value: "2017学年",
                  label: "2017学年",
                  children: [
                    {
                      value: "上学期",
                      label: "上学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      value: "下学期",
                      label: "下学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
                {
                  value: "2018学年",
                  label: "2018学年",
                  children: [
                    {
                      value: "上学期",
                      label: "上学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      value: "下学期",
                      label: "下学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
          ],
        },
        {
          value: "数学学院",
          label: "数学学院",
          children: [
            {
              value: "数据结构",
              label: "数据结构",
              children: [
                {
                  value: "2017学年",
                  label: "2017学年",
                  children: [
                    {
                      value: "上学期",
                      label: "上学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      value: "下学期",
                      label: "下学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
                {
                  value: "2018学年",
                  label: "2018学年",
                  children: [
                    {
                      value: "上学期",
                      label: "上学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      value: "下学期",
                      label: "下学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
            {
              vaule: "算法",
              label: "算法",
              children: [
                {
                  value: "2017学年",
                  label: "2017学年",
                  children: [
                    {
                      value: "上学期",
                      label: "上学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      value: "下学期",
                      label: "下学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
                {
                  value: "2018学年",
                  label: "2018学年",
                  children: [
                    {
                      value: "上学期",
                      label: "上学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                    {
                      value: "下学期",
                      label: "下学期",
                      children: [
                        {
                          value: "张老师",
                          label: "张老师",
                        },
                        {
                          value: "王老师",
                          label: "王老师",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
          ],
        },
      ],

      studentOptions: [
        {
          value: "信息工程学院",
          label: "信息工程学院",
          children: [
            {
              value: "2017级",
              label: "2017级",
              children: [
                {
                  value: "计算机科学与技术",
                  label: "计算机科学与技术",
                  children: [
                    {
                      value: "计算机1班",
                      label: "计算机1班",
                      children: [
                        {
                          value: "李明",
                          label: "李明",
                        },
                        {
                          value: "源华",
                          label: "源华",
                        },
                        {
                          value: "佳琪",
                          label: "佳琪",
                        },
                      ],
                    },
                    {
                      value: "计算机2班",
                      label: "计算机2班",
                      children: [
                        {
                          value: "李明",
                          label: "李明",
                        },
                        {
                          value: "源华",
                          label: "源华",
                        },
                        {
                          value: "佳琪",
                          label: "佳琪",
                        },
                      ],
                    },
                  ],
                },
                {
                  value: "软件工程",
                  label: "软件工程",
                  children: [
                    {
                      value: "软件1班",
                      label: "软件1班",
                      children: [
                        {
                          value: "李明",
                          label: "李明",
                        },
                        {
                          value: "源华",
                          label: "源华",
                        },
                        {
                          value: "佳琪",
                          label: "佳琪",
                        },
                      ],
                    },
                    {
                      value: "软件2班",
                      label: "软件2班",
                      children: [
                        {
                          value: "李明",
                          label: "李明",
                        },
                        {
                          value: "源华",
                          label: "源华",
                        },
                        {
                          value: "佳琪",
                          label: "佳琪",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
            {
              value: "2018级",
              label: "2018级",
              children: [
                {
                  value: "计算机科学与技术",
                  label: "计算机科学与技术",
                  children: [
                    {
                      value: "计算机1班",
                      label: "计算机1班",
                      children: [
                        {
                          value: "李明",
                          label: "李明",
                        },
                        {
                          value: "源华",
                          label: "源华",
                        },
                        {
                          value: "佳琪",
                          label: "佳琪",
                        },
                      ],
                    },
                    {
                      value: "计算机2班",
                      label: "计算机2班",
                      children: [
                        {
                          value: "李明",
                          label: "李明",
                        },
                        {
                          value: "源华",
                          label: "源华",
                        },
                        {
                          value: "佳琪",
                          label: "佳琪",
                        },
                      ],
                    },
                  ],
                },
                {
                  value: "软件工程",
                  label: "软件工程",
                  children: [
                    {
                      value: "软件1班",
                      label: "软件1班",
                      children: [
                        {
                          value: "李明",
                          label: "李明",
                        },
                        {
                          value: "源华",
                          label: "源华",
                        },
                        {
                          value: "佳琪",
                          label: "佳琪",
                        },
                      ],
                    },
                    {
                      value: "软件2班",
                      label: "软件2班",
                      children: [
                        {
                          value: "李明",
                          label: "李明",
                        },
                        {
                          value: "源华",
                          label: "源华",
                        },
                        {
                          value: "佳琪",
                          label: "佳琪",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
          ],
        },
      ],
      title: "",
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 教师课程管理表格数据
      courseList: [],
      // 表单校验
      rules: {
        schoolYearId: [
          { required: true, message: "请选择学年", trigger: "blur" },
        ],
        termId: [{ required: true, message: "请选择学期", trigger: "blur" }],
        collegeId: [{ required: true, message: "请选择学院", trigger: "blur" }],
        majorId: [{ required: true, message: "请选择专业", trigger: "blur" }],
        classesId: [{ required: true, message: "请选择班级", trigger: "blur" }],
        courseId: [{ required: true, message: "请选择课程", trigger: "blur" }],
        userId: [{ required: true, message: "请选择学生", trigger: "blur" }],
      },

      //课程信息
      courseOptions: [
        {
          id: "",
          name: "",
        },
      ],
      majorOptions: [
        {
          id: "",
          name: "",
        },
      ],
      classesOptions: [
        {
          id: "",
          name: "",
        },
      ],
      studentOptions: [
        {
          userId: "",
          xm: "",
        },
      ],
			  filterText: "",
    };
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
  created() {
    this.getList();
  },
  methods: {
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    resetCourseOptions() {
      this.courseOptions = [
        {
          id: "",
          name: "",
        },
      ];
    },

    resetTermOptions() {},
    resetCollegeOptions() {},

    resetMajorOptions() {
      this.majorOptions = [
        {
          id: "",
          name: "",
        },
      ];
    },

    resetClassesOptions() {
      this.classesOptions = [
        {
          id: "",
          name: "",
        },
      ];
    },

    resetStudentOptions() {
      this.studentOptions = [
        {
          userId: "",
          xm: "",
        },
      ];
    },
    /** 查询学生课程管理列表 */
    getList() {
      this.loading = true;
      listStudentCourse(this.queryParams).then((response) => {
        this.courseList = response.rows;
        console.log("courseList: ", this.courseList);
        this.total = response.total;
        this.loading = false;
      });
    },
    // 搜索栏中根据选择的学年学期学院查询下面的课程和专业信息
    searchMajorAndCourse() {
      // this.queryParams.courseId=null,
      // this.resetCourseOptions();

      if (this.queryParams.classesId != null) {
        this.queryParams.classesId = null;
        this.resetClassesOptions();
      }
      if (this.queryParams.userId != null) {
        this.queryParams.userId = null;
        this.resetStudentOptions();
      }
      // listCourse(this.queryParams).then((res) => {
      //      this.courseOptions = res.rows;
      //      console.log("courseOptions:",this.courseOptions);
      // });

      (this.queryParams.majorId = null), this.resetMajorOptions();

      if (this.queryParams.collegeId !== "") {
        listMajor({
          collegeId: this.queryParams.collegeId,
        }).then((res) => {
          this.majorOptions = res.rows;
        });
      }
    },

    // 根据选取的专业获取专业下面的班级
    searchClassesByMajor() {
      console.log(" searchClassByMajor");
      this.queryParams.classesId = "";
      this.resetClassesOptions();
      if (this.queryParams.userId != null) {
        this.queryParams.userId = null;
        this.resetStudentOptions();
      }

      if (this.queryParams.majorId !== "") {
        listClasses({
          majorId: this.queryParams.majorId,
        }).then((res) => {
          this.classesOptions = res.rows;
          console.log("classesOptions: ", this.classesOptions);
        });
      }
    },

    // 根据选取的班级获取班级下面的学生
    searchStudentsByClasses() {
      this.queryParams.userId = "";
      this.resetStudentOptions();

      listStudent(this.queryParams).then((response) => {
        this.studentOptions = response.rows;
        console.log("studentOptions: ", this.studentOptions);
      });
    },

    // 搜索栏中根据选择的学年学期学院查询下面的课程和专业信息
    addMajorAndCourse() {
      // this.form.courseId=null,
      // this.resetCourseOptions();
      console.log("查询中的form: ", this.form);

      if (this.form.userId != null) {
        this.form.userId = null;
        this.resetStudentOptions();
      }

      // listCourse(this.form).then((res) => {
      //   this.courseOptions = res.rows;
      //   console.log("courseOptions:",this.courseOptions);
      // });

      (this.form.majorId = null), this.resetMajorOptions();
      if (this.form.classesId != null) {
        this.form.classesId = "";
        this.resetClassesOptions();
      }
      if (this.form.collegeId !== "") {
        listMajor(this.form).then((res) => {
          this.majorOptions = res.rows;
          console.log("majorOptions:", this.majorOptions);
        });
      }
    },
    // 根据选取的专业获取专业下面的班级
    addClassesByMajor() {
      console.log("addClassByMajor");
      this.form.classesId = "";
      this.resetClassesOptions();
      if (this.form.userId != null) {
        this.form.userId = null;
        this.resetStudentOptions();
      }

      if (this.form.majorId !== "") {
        listClasses({
          majorId: this.form.majorId,
        }).then((res) => {
          this.classesOptions = res.rows;
          console.log("classesOptions: ", this.classesOptions);
        });
      }
    },
    // 根据选取的班级获取班级下面的学生
    addStudentByClasses() {
      this.form.userId = "";
      this.resetStudentOptions();
      listStudent(this.form).then((response) => {
        this.studentOptions = response.rows;
        console.log("studentOptions: ", this.studentOptions);
      });
    },
    // 表单重置
    reset() {
      this.form = {
        schoolYearId: null,
        collegeId: null,
        termId: null,
        majorId: null,
        classesId: null,
        userId: null,
        courseId: null,
        id: null,
      };
      this.resetForm("form");
      this.resetOptions();
    },
    // 重置学期，学院等选择数组
    resetOptions() {
      this.resetTermOptions();
      this.resetCollegeOptions();
      this.resetMajorOptions();
      this.resetClassesOptions();
      this.resetStudentOptions();
    },
    handleNodeClick(data) {
      console.log(data);
    },

    handleAdd() {
      this.reset();
      this.title = "新增学生课程信息";
      this.open = true;
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.resetForm("queryForm");
      this.resetOptions();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
      this.resetOptions();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getCourse(id).then((response) => {
        this.form = response.data;
        console.log("获取的form信息： ", this.form);
        this.open = true;
        this.title = "修改学生课程管理";

        this.form.courseId = response.data.orgCourse.id;
        this.form.userId = response.data.sysStudent.userId;

        this.termNameOptions[0].id = response.data.termId;
        this.termNameOptions[0].termName = response.data.termName;
        this.collegeOptions[0].id = response.data.collegeId;
        this.collegeOptions[0].name = response.data.collegeName;
        // this.courseOptions[0].id=response.data.orgCourse.id;
        // this.courseOptions[0].courseName=response.data.orgCourse.courseName;
        this.majorOptions[0].id = response.data.majorId;
        this.majorOptions[0].name = response.data.majorName;

        this.classesOptions[0].id = response.data.classesId;
        this.classesOptions[0].name = response.data.classesName;

        this.studentOptions[0].userId = response.data.sysStudent.userId;
        this.studentOptions[0].xm = response.data.sysStudent.xm;
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除学生课程管理编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delCourse(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有学生课程管理数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportCourse(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateCourse(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCourse(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  },
};
</script>

<style>
::v-deep .dialog-footer:after {
  content: "";
  display: table;
  clear: both;
}
</style>
